package org.javaboy.vhr.service;

import org.javaboy.vhr.mapper.EmployeeecMapper;
import org.javaboy.vhr.model.Employee;
import org.javaboy.vhr.model.Employeeec;
import org.javaboy.vhr.vo.EmpEcVo;
import org.javaboy.vhr.vo.RespPageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service
public class EmployeeecService {

    @Autowired
    private EmployeeecMapper employeeecMapper;

    public RespPageBean getEmployeeecByPage(Integer page, Integer size, Employeeec employeeec, Date[] beginDateScope) {
        if (page != null && size != null) {
            page = (page - 1) * size;
        }
        List<EmpEcVo> data = employeeecMapper.getEmployeeecByPage(page, size, employeeec, beginDateScope);
        List<EmpEcVo> result = new ArrayList<>();
        for(EmpEcVo v : data){
           if(v.getEcType().equals(1)) {
               v.setEcTypeString("罚");
               result.add(v);
           }else{
               v.setEcTypeString("奖");
               result.add(v);
           }
        }
        Long total = employeeecMapper.getTotal(employeeec, beginDateScope);
        RespPageBean bean = new RespPageBean();
        bean.setData(result);
        bean.setTotal(total);
        return bean;
    }

    public List<Employee> getTotalEmployee(){
        return employeeecMapper.getTotalEmployee();
    }

    public Integer add(Employeeec employeeec){
        return employeeecMapper.insertSelective(employeeec);
    }

    public int update(Employeeec employeeec){
        return employeeecMapper.updateByPrimaryKey(employeeec);
    }

    public int delete(Integer id){
        return employeeecMapper.deleteByPrimaryKey(id);
    }
}
